package com.wisdomsky.project.param.controller;

import com.wisdomsky.commonUtil.pojo.build.BuildResponse;
import com.wisdomsky.project.param.pojo.Params;
import com.wisdomsky.project.param.service.logic.ParamsLogicService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("")
@Slf4j
public class ParamsController {

    @Autowired
    private ParamsLogicService logicService;

    @RequestMapping(value = "roles", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    private String roles(@RequestBody Params params){
        BuildResponse response = new BuildResponse();
        try {
            response = logicService.retrieveRoles(params,"code", "name");
        } catch (Exception e) {
            log.info("info: " + params.getSerialNo());
            return response.failed_100001(e);
        }
        return response.getJSONResponse();
    }

    @RequestMapping(value = "system", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    private String system(@RequestBody Params params){
        BuildResponse response = new BuildResponse();
        try {
            response = logicService.retrieveSystem("code", "name");
        } catch (Exception e) {
            log.info("info: " + params.getSerialNo());
            return response.failed_100001(e);
        }
        return response.getJSONResponse();
    }

    @RequestMapping(value = "recurrent", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    private String recurrent(@RequestBody Params params){
        BuildResponse response = new BuildResponse();
        try {
            response = logicService.retrieveRecurrent("code", "name");
        } catch (Exception e) {
            log.info("info: " + params.getSerialNo());
            return response.failed_100001(e);
        }
        return response.getJSONResponse();
    }

    @RequestMapping(value = "repair/state", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    private String repairState(@RequestBody Params params){
        BuildResponse response = new BuildResponse();
        try {
            response = logicService.retrieveRepairState( "code", "name");
        } catch (Exception e) {
            log.info("info: " + params.getSerialNo());
            return response.failed_100001(e);
        }
        return response.getJSONResponse();
    }

    @RequestMapping(value = "project/state", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    private String projectState(@RequestBody Params params){
        BuildResponse response = new BuildResponse();
        try {
            response = logicService.retrieveProjectState(params,"code", "name");
        } catch (Exception e) {
            log.info("info: " + params.getSerialNo());
            return response.failed_100001(e);
        }
        return response.getJSONResponse();
    }

}
